<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%special_card_ask_log}}".
 *
 * @property int $id
 * @property int $special_card_id
 * @property int $time
 * @property string $app_post_data
 * @property string $post_data
 * @property string $divided_payments_order_data
 * @property string $send_return_msg
 * @property int $old_status
 * @property int $new_status
 * @property string $api_return_code
 * @property string $api_return_msg
 * @property string $serial_number
 *
 * @property SpecialCard $specialCard
 * @property SpecialCardBankBackLog[] $specialCardBankBackLogs
 */
class SpecialCardAskLog extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%special_card_ask_log}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['special_card_id', 'time', 'serial_number'], 'required'],
            [['special_card_id', 'time', 'old_status', 'new_status'], 'integer'],
            [['app_post_data', 'post_data', 'divided_payments_order_data', 'api_return_msg'], 'string'],
            [['send_return_msg', 'api_return_code'], 'string', 'max' => 10],
            [['serial_number'], 'string', 'max' => 20],
            [['special_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => SpecialCard::className(), 'targetAttribute' => ['special_card_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'special_card_id' => Yii::t('app', 'Special Card ID'),
            'time' => Yii::t('app', 'Time'),
            'app_post_data' => Yii::t('app', 'App Post Data'),
            'post_data' => Yii::t('app', 'Post Data'),
            'divided_payments_order_data' => Yii::t('app', 'Divided Payments Order Data'),
            'send_return_msg' => Yii::t('app', 'Send Return Msg'),
            'old_status' => Yii::t('app', 'Old Status'),
            'new_status' => Yii::t('app', 'New Status'),
            'api_return_code' => Yii::t('app', 'Api Return Code'),
            'api_return_msg' => Yii::t('app', 'Api Return Msg'),
            'serial_number' => Yii::t('app', 'Serial Number'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSpecialCard()
    {
        return $this->hasOne(SpecialCard::className(), ['id' => 'special_card_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSpecialCardBankBackLogs()
    {
        return $this->hasMany(SpecialCardBankBackLog::className(), ['for_serial_number' => 'serial_number']);
    }
}
